﻿$(function () {
    $(".backIframe").on("click", function () {
        //var index = parent.layer.getFrameIndex(window.name);
        parent.selfLayer.closeIframe();
    });
});

var bAjax = {
    isDebug: false,
    get: function (url, data, callback, isLoding) {
        var async = true;
        if (isLoding) {
            async = false;
        }
        $.ajax({
            type: "get",
            dataType: "json",
            url: url,
            data: data,
            cache: false,
            async: async,
            beforeSend: function (xhr) {
                if (!isLoding) {
                    layer.load(0, { shade: 0.01 });
                }
            },
            success: function (result) {
                bAjax.consoleLog("url:" + url + ",result:" + JSON.stringify(result));
                if (result.Code == 200) {
                    callback(result);
                } else {
                    layer.alert(result.msg);
                }
            },
            error: function (xhr, type, errorThrown) {
                //alert("js:error,type=" + type);
            },
            complete: function (xhr, status) {
                if (!isLoding) {
                    layer.closeAll('loading');
                }
            }
        });

    },
    post: function (url, data, callback, isLoding) {
        $.ajax({
            type: "post",
            dataType: "json",
            url: url,
            data: data,
            cache: false,
            async: true,
            beforeSend: function (xhr) {
                if (!isLoding) {
                    layui.layer.load(0, { shade: 0.01 });
                }
            },
            success: function (result) {
                console.log(result);

                if (result.code == 200) {
                    layui.layer.alert(result.msg);
                    callback(result);
                } else {
                    layui.layer.alert(result.msg);
                }
            },
            error: function (xhr, type, errorThrown) {
                alert("js:error,type=" + JSON.stringify(xhr));
            },
            complete: function (xhr, status) {
                if (!isLoding) {
                    layui.layer.closeAll('loading');
                }
            }
        });
    },
};
var myEchart = {
    inti: function (el, result, titleText, xAxisName) {
        var myChart = echarts.init(document.getElementById(el));
        var seriesdata = [];
        var legenddata = [];
        var xAxis = [];
        for (var i = 0; i < result.length; i++) {
            result.data = JSON.parse(result[i].data);
            var data = [];
            legenddata.push(result.data[0].title + "年");
            for (var j = 0; j < result.data.length; j++) {
                data.push(result.data[j].Number);
                if (i == 0)
                    xAxis.push(result.data[j].name + "");
            }
            seriesdata.push({
                name: result.data[0].title + "年",
                data: data,
                type: 'bar'
            });
        }
        option = {
            legend: {
                textStyle: {
                    fontSize: 12
                },
                y: 35,
                data: legenddata
            },
            title: {
                text: titleText,
                x: 'center',
                textStyle: {
                    fontSize: 18
                },
                // 
            },

            tooltip: {
                trigger: 'axis',
                textStyle: {//图例文字的样式
                    fontSize: 16
                }
            },
            toolbox: {
                x: '85%',
                y: 20,
                feature: {
                    magicType: {
                        show: true,
                        type: ['line', 'bar'],
                        title: { line: '折线图切换', bar: '柱形图切换' },
                        iconStyle: {
                            emphasis: {
                                textPosition: 'top'
                            }
                        }
                    },
                    saveAsImage: {
                        show: true, title: '下载', iconStyle: {
                            emphasis: {
                                textPosition: 'top'
                            }
                        }
                    }
                },
                textStyle: {//图例文字的样式
                }
            },
            xAxis: {
                name: xAxisName,
                axisLabel: {
                    rotate: 60,
                    interval: 0

                },
                textStyle: {//图例文字的样式
                    fontSize: 16
                },
                data: xAxis
            },
            yAxis: {
                type: 'value',
                name: '',
                margin: 10,
                textStyle: {
                },
                axisLabel: {
                    interval: 'auto',
                    rotate: -15,
                    margin: 18,
                    formatter: '{value}次'
                },
                axisLine: {    // 轴线
                    show: true,
                    lineStyle: {
                        type: 'dashed',
                        width: 1
                    }
                }
            },
            series: seriesdata
        }
        myChart.clear();
        myChart.setOption(option);

    },
    newInti: function () {
    },
    LoadTable: function (result) {
        var thead = "<tr><td></td>";
        var tbody = "";
        for (var i = 0; i < result.length; i++) {
            result.data = JSON.parse(result[i].data);
            tbody += "<tr><td>" + result.data[0].title + "年</td>";
            for (var j = 0; j < result.data.length; j++) {

                tbody += "<td><a onclick='oenpage(" + result.data[j].name + "," + result.data[0].title + ")'>" + result.data[j].Number + "</a></td>";
                if (i == 0)
                    thead += "<td>" + result.data[j].name + "</td>";
            }
            tbody += "/<tr>";
        }
        thead += "</tr>";

        $("#thdata").html(thead);
        $("#tbdata").html(tbody);

    }
}
var picker = {
    //获取数据字典
    GetTypeList: function (form, keyword, data) {
        $.get("/Dictionary/GetDictionaryType", keyword, function (result) {
            console.log(result);
            if (result.code == 200) {
                var resultdata = result.result.data;
                var options = '<option value="">请选择</option>';
                for (var i = 0; i < resultdata.length; i++) {
                    if (data == resultdata[i].type)
                        options += '<option value="' + resultdata[i].type + '" selected>' + resultdata[i].type + '</option>';
                    else
                        options += '<option value="' + resultdata[i].type + '">' + resultdata[i].type + '</option>';
                }
                $("#Type").html(options);
                form.render();
            } else {
                alert()
            }
        });
    },
    GetTypeDictionaryList: function (form, keyword, data) {
        $.get("/Dictionary/GetList", keyword, function (result) {
            console.log(result);
            if (result.code == 200) {
                var resultdata = result.result.data;
                var options = '<option value="">请选择</option>';
                for (var i = 0; i < resultdata.length; i++) {
                    if (data == resultdata[i].id)
                        options += '<option value="' + resultdata[i].id + '" selected>' + resultdata[i].name + '</option>';
                    else
                        options += '<option value="' + resultdata[i].id + '">' + resultdata[i].name + '</option>';
                }
                $("#Type").html(options);
                form.render();
            } else {
                alert()
            }
        });
    },
    //获取省市区
    GetProvinceList: function (form, keyword, el, data) {
        $.get("/Area/GetList", keyword, function (result) {
            console.log(result);
            if (result.code == 200) {
                var resultdata = result.result.data;
                var options = '<option value="">请选择</option>';
                for (var i = 0; i < resultdata.length; i++) {
                    if (data == resultdata[i].yunCode)
                        options += '<option value="' + resultdata[i].yunCode + '" selected>' + resultdata[i].areaName + '</option>';
                    else
                        options += '<option value="' + resultdata[i].yunCode + '">' + resultdata[i].areaName + '</option>';
                }
                $("#" + el).html(options);
                form.render();
            } else {
                alert()
            }
        });
    },

};
function windowOpen(url) {
    try {
        window.showModalDialog(url, window, 'height=390,width=500,top=200,left=200,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,fullscreen=0');
    } catch (e) {
        try {
            return window.open(url, window, 'dialogHeight=390px;dialogwidth=500px;help=no;scrollbars=no;status=no;dialogLeft=200px;dialogTop=200px;');
        } catch (e) {
            window.open(url, '', 'width=800,height=300');
            //window.showModalDialog(url, new Object(), "dialogWidth=500px;dialogHeight=390px");
        }
    }
}

